package com.koalac.ironman.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;

/**
 * 
 * @description 简单的消息提醒，
 * @author chenxiaohua
 * @Date 2014-06-9
 */
public class ArmisiToast extends Toast {

	public ArmisiToast(Context context) {
		super(context);
	}

	/**
	 * 显示多长时间
	 * 
	 * @param t
	 * @description
	 * @author chenxiaohua
	 * @Date 2014-06-9
	 */
	public void setShowtTime(int t) {
		this.setDuration(t);
	}

	/**
	 * 
	 * @param context
	 * @param msg
	 * @param showtime
	 * @description 展现当前的toast消息，确保显示
	 * @author chenxiaohua
	 * @Date 2014-06-9
	 */
	public final static void showToastMsg(final Context context,
			final String msg, final int showtime) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				Looper.prepare();
				Toast.makeText(context, msg, showtime).show();
				Looper.loop();
			}
		}).start();
	}

	public final static void showToastDialogMsg(final Context context,
			final String msg) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				Looper.prepare();
				try {
					AlertDialog.Builder builder = new AlertDialog.Builder(
							context);
					builder.setTitle(null);
					builder.setMessage(msg);
					// 设置确定按钮
					builder.setPositiveButton("确定",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									dialog.dismiss();
								}
							});
					builder.create().show();
				} catch (Exception ex) {
					Log.i("ssLogout eerr:", "", ex);
				}
				Looper.loop();
			}
		}).start();
	}
}
